import 'package:environmental_les_app/common/routes/route_names.dart';
import 'package:environmental_les_app/common/style/colours.dart';
import 'package:environmental_les_app/common/widgets/attachment_select_widget.dart';
import 'package:environmental_les_app/common/widgets/button_public_rect.dart';
import 'package:environmental_les_app/common/widgets/common_widget.dart';
import 'package:environmental_les_app/common/widgets/input_row_item.dart';
import 'package:environmental_les_app/common/widgets/required_field_text.dart';
import 'package:environmental_les_app/common/widgets/text_area.dart';
import 'package:flutter_clx_base/flutter_clx_base.dart';

import 'index.dart';
import 'widgets/enterprise_selection.dart';
import 'widgets/personnel_selection.dart';

class CreateTaskPage extends GetView<CreateTaskController> {
  const CreateTaskPage({super.key});

  // 主视图
  Widget _buildView() {
    return baseCardContainer(content: [
      InputRowItem(
          isRequired: true,
          title: "任务标题",
          hintText: "请输入任务标题",
          keyboardType: TextInputType.text,
          focusNode: FocusNode(),
          controller: TextEditingController(),
          showLine: true),
      operateRowItem(
          title: "详细地址",
          content: "北京市海淀区上地十街10号",
          isRequired: true,
          showArrow: false,
          showLine: true),
      operateRowItem(
          title: "站点类型",
          hintText: "请选择业务来源",
          content: controller.selectedSiteType,
          isRequired: true,
          onTap: () {
            Get.toNamed(AppRoutes.locationSelectPage);
          },
          showArrow: true,
          showLine: true),
      operateRowItem(
          title: "站台名称",
          content: controller.stationName,
          isRequired: true,
          showArrow: false,
          showLine: true),
      operateRowItem(
          title: "任务地点",
          content: controller.taskLocation,
          isRequired: true,
          showArrow: false,
          showLine: true),
      Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          vGap10,
          const RequiredFieldText(
            text: "任务说明",
            titleColor: Colours.text969,
            titleFontSize: 15,
            titleFontWeight: FontWeight.w400,
          ),
          vGap16,
          TextArea(
            controller: TextEditingController(),
            hintText: "请输入内容",
            minLines: 2,
            maxLines: 5,
            maxLength: 100,
          ),
        ],
      ),
      operateRowItem(
          title: "开始时间",
          content: "2023-03-15 10:00",
          isRequired: true,
          onTap: () {},
          showArrow: true,
          showLine: true),
      operateRowItem(
          title: "截止时间",
          content: "2023-03-15 10:00",
          isRequired: true,
          onTap: () {},
          showArrow: true,
          showLine: true),
      Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          vGap10,
          const RequiredFieldText(
            text: "备注",
            titleColor: Colours.text969,
            titleFontSize: 15,
            titleFontWeight: FontWeight.w400,
          ),
          vGap16,
          TextArea(
            controller: TextEditingController(),
            hintText: "请输入内容",
            minLines: 2,
            maxLines: 5,
            maxLength: 100,
          ),
        ],
      ),
      AttachmentSelectWidget(
        initialFiles: controller.attachments,
        onChanged: (files) {
          controller.attachments = files;
          controller.update(["patrol"]);
        },
      ),
      operateRowItem(
          title: "派遣方式",
          content: "",
          isRequired: true,
          rightWidget: Row(
            children: [
              customRadio(
                value: 1,
                groupValue: controller.dispatchType,
                onChanged: (value) {
                  controller.dispatchType = value!;
                  controller.update(["create_task"]);
                },
                title: '内部人员',
              ),
              hGap20,
              customRadio(
                value: 2,
                groupValue: controller.dispatchType,
                onChanged: (value) {
                  controller.dispatchType = value!;
                  controller.update(["create_task"]);
                },
                title: '外部企业',
              ),
            ],
          ),
          showLine: true),
      operateRowItem(
          title: "派遣对象",
          hintText: "请选择派遣对象",
          content: controller.selectedSiteType,
          isRequired: true,
          onTap: () {
            if (controller.dispatchType == 1) {
              Get.to(const PersonnelSelectionWidget());
              return;
            }
            Get.to(const EnterpriseSelectionWidget());
          },
          showArrow: true,
          showLine: true),
    ]);
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<CreateTaskController>(
      init: CreateTaskController(),
      id: "create_task",
      builder: (_) {
        return MyScaffold(
          title: "创建任务",
          bottomButton: Container(
            color: Colors.white,
            padding:
                const EdgeInsets.only(top: 16, bottom: 20, right: 10, left: 10),
            child: ButtonPublicRect(
                minWidth: double.infinity, text: "提交", onPressed: () {}),
          ),
          children: [
            _buildView(),
          ],
        );
      },
    );
  }
}
